﻿#pragma
#ifndef CUSTOMSLEEPTOOL_H
#define CUSTOMSLEEPTOOL_H
#include <iostream>
#include <thread>
using namespace std;

class CustomSleepTool {
public:
	/// <summary>
	/// 设置毫秒
	/// </summary>
	/// <param name="ms">毫秒</param>
	void Sleep(unsigned int ms)
	{
		auto beg = clock();
		for (int i = 0; i < ms; i++)
		{
			this_thread::sleep_for(1ms);
			if ((clock() - beg) / (CLOCKS_PER_SEC / 1000) >= ms)
				break;
		}
	}

	/// <summary>
	/// 单例
	/// </summary>
	/// <returns></returns>
	static CustomSleepTool* Get()
	{
		static CustomSleepTool cst;
		return &cst;
	}
};

#endif